import time

import openpyxl
import Common
class createTestData:
    def __init__(self):
        # self.createLoginTestData()
        # time.sleep(3)
        # self.createRegisterTestData()
        self.createBankCardTestData()
        # self.createFundTestData()
        # self.createLoanTestData()

    def createLoginTestData(self):
        data={"username": "admin", "password": "123456", "username2": "admin", "password2": "1234567",
         "target": "密码错误"}
        workbook = openpyxl.Workbook('./用例测试数据.xlsx')
        sheet_name="登录用例测试数据"
        workbook.create_sheet(sheet_name)
        sheet = workbook[sheet_name]
        headerlist=list(data.keys())
        sheet.append(headerlist)
        datalist=[{"username":"lisi","password":"123456","username2": "", "password2": "","target":"个人理财系统"},
                  {"username": "admin", "password": "123456","username2": "", "password2": "", "target": "后台管理系统"},
                  {"username": "lisi3", "password": "123!@#$%^%&456","username2": "", "password2": "", "target": "个人理财系统"},
                  {"username": "lisi", "password": "123456", "username2": "lisi3", "password2": "123456",
                   "target": "用户名不存在"},
                  {"username": "lisi", "password": "123456", "username2": "lisi", "password2": "1234567",
                   "target": "密码错误"},
                  {"username": "admin", "password": "123456", "username2": "admin1", "password2": "123456",
            "target": "用户名不存在"},{"username": "admin", "password": "123456", "username2": "admin", "password2": "1234567",
            "target": "密码错误"}
                  ]
        for i in datalist:
            sheet.append(list(i.values()))
        workbook.save("用例测试数据.xlsx")

    def createBankCardTestData(self):
        data={"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardtype":"1","target":1,"targetbalance":"10000","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""}
        workbook = openpyxl.load_workbook('./用例测试数据.xlsx')
        sheet_name="银行用例测试数据"
        workbook.create_sheet(sheet_name)
        sheet = workbook[sheet_name]
        headerlist=list(data.keys())
        sheet.append(headerlist)
        datalist=[{"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardtype":"1","target":"1","targetbalance":"10000","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456","bankCardName":"伊拉克国民银行","bankCardNum":Common.generateRandomNumber(17),"bankCardtype":"1","target":"0","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "1","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "2","target": "1","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "0","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "1","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "1","targetbalance":"","rebankCardName": "交通银行","rebankCardNum": "","rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "1","targetbalance":"","rebankCardName": "","rebankCardNum": Common.generateRandomNumber(16),"rebankCardtype": ""},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "0","targetbalance":"","rebankCardName": "","rebankCardNum": Common.generateRandomNumber(17),"rebankCardtype": "" },
                  {"username": "lisi", "password": "123456", "bankCardName": "伊拉克国民银行","bankCardNum": Common.generateRandomNumber(16), "bankCardtype": "1","target": "1","targetbalance":"","rebankCardName": "","rebankCardNum": "","rebankCardtype": "2"}
                  ]
        for i in datalist:
            sheet.append(list(i.values()))
        workbook.save("用例测试数据.xlsx")
    def createRegisterTestData(self):
        data={"username": "wangwu", "password": "123456", "repassword": "123456", "target": "1","targetConfirm":""}
        workbook = openpyxl.load_workbook('./用例测试数据.xlsx')
        sheet_name="注册用例测试数据"
        workbook.create_sheet(sheet_name)
        sheet = workbook[sheet_name]
        headerlist=list(data.keys())
        sheet.append(headerlist)
        datalist=[{"username": "wangwu", "password": "123456", "repassword": "123456", "target": "1","targetConfirm":""},
                  {"username":"wangwu1","password":"123456","repassword":"123456","target":"1","targetConfirm":""},
                  {"username":"wangwu","password":"123456","repassword":"1234567","target":"0","targetConfirm":""},
                  {"username":"wangwu","password":"123456","repassword":"","target":"0","targetConfirm":""},
                  {"username":"wangwu","password":"","repassword":"","target":"","targetConfirm":"密码为空"}
                  ]
        for i in datalist:
            sheet.append(list(i.values()))
        workbook.save("用例测试数据.xlsx")

    def createFundTestData(self):
        data={"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": 1,"buynid":"1","buybtnname": "","paypwd":"666666","balance":"1000000","targetbalance":"999900","targetConfirm":"买入成功!"}
        workbook = openpyxl.load_workbook('./用例测试数据.xlsx')
        sheet_name="基金理财用例测试数据"
        workbook.create_sheet(sheet_name)
        sheet = workbook[sheet_name]
        headerlist=list(data.keys())
        sheet.append(headerlist)
        datalist=[{"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666666","balance":"1000000","targetbalance":"999900","targetConfirm":"买入成功!"},
                  {"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666667","balance":"1000000","targetbalance":"1000000","targetConfirm":"买入失败!"},
                  {"username": "lisi4", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666666","balance":"55","targetbalance":"55","targetConfirm":"买入失败!，银行卡余额不足"},
                  {"username": "lisi5", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666666","balance":"","targetbalance":"","targetConfirm":"买入失败!，请绑定银行卡"},
                  {"username": "lisi", "password": "123456","bankCardName":"伊朗中央银行","bankCardNum":Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666666","balance":"1000000","targetbalance":"995000","targetConfirm":"买入成功!"},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16),"bankCardNumber": "1","buynid":"1","buybtnname": "","paypwd":"666667","balance": "1000000","targetbalance": "1000000", "targetConfirm": "买入失败!"},
                  {"username": "lisi4", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16),"bankCardNumber": "1", "buynid": "1","buybtnname": "", "paypwd": "666666", "balance": "55","targetbalance": "55", "targetConfirm": "买入失败!，银行卡余额不足"},
                  {"username": "lisi5", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1","buybtnname": "", "paypwd": "666666","balance": "","targetbalance": "","targetConfirm": "买入失败!，请绑定银行卡"},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1", "buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "1000000","targetbalance": "997000", "targetConfirm": "买入成功!"},
                  {"username": "lisi", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1", "buybtnname": "广发多元新兴股票","paypwd": "666667","balance": "1000000", "targetbalance": "1000000", "targetConfirm": "买入失败!"},
                  {"username": "lisi4", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16),"bankCardNumber": "1", "buynid": "1", "buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "55", "targetbalance": "55", "targetConfirm": "买入失败!，银行卡余额不足"},
                  {"username": "lisi5", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1","buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "100000","targetbalance": "100000", "targetConfirm": "买入失败!，请绑定银行卡"},
                  {"username": "lisi6", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1", "buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "1000000", "targetbalance": "1000000","targetConfirm": "买入失败!,请前往个人信息设置支付密码"},
                  {"username": "lisi7", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "3", "buynid": "1","buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "1000000", "targetbalance": "997000", "targetConfirm": "买入成功!"},
                  {"username": "lisi7", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "3", "buynid": "1","buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "1000000", "targetbalance": "997000", "targetConfirm": "买入成功!"},
                  {"username": "lisi5", "password": "123456", "bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "bankCardNumber": "1","buynid": "1","buybtnname": "广发多元新兴股票","paypwd": "666666","balance": "100000","targetbalance": "100000",   "targetConfirm": "买入失败!，请绑定银行卡"}
                  ]
        for i in datalist:
            sheet.append(list(i.values()))
        workbook.save("用例测试数据.xlsx")
    def createLoanTestData(self):
        data={"username": "lisi", "password": "123456", "adminUsername": "", "adminPassword": "","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "10000", "targetbalance": "","term": "10", "confirm": "","targetConfirm": "申请成功!请等待管理员审核!"}

        workbook = openpyxl.load_workbook('./用例测试数据.xlsx')
        sheet_name="贷款用例测试数据"
        workbook.create_sheet(sheet_name)
        sheet = workbook[sheet_name]
        headerlist=list(data.keys())
        sheet.append(headerlist)
        datalist=[
            {"username": "lisi", "password": "123456", "adminUsername": "", "adminPassword": "","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "10000", "targetbalance": "","term": "10", "confirm": "","targetConfirm": "申请成功!请等待管理员审核!"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "10000","targetbalance": "20000","term": "10","confirm": "", "targetConfirm": "申请成功!请等待管理员审核!"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "10000","targetbalance": "20000", "term": "10","confirm": "申请失败，请先绑定个人信息", "targetConfirm": "申请失败!,请先绑定银行卡"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "100000000000000000","targetbalance": "100000000000010000","term": "10","confirm": "申请失败，请先绑定个人信息",  "targetConfirm": "申请失败"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "100","targetbalance": "100000000000010000","term": "10","confirm": "申请失败，请先绑定个人信息", "targetConfirm": "申请失败，申请额度必须是100的整数倍"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "100","targetbalance": "100000000000010000","term": "366","confirm": "申请失败，请先绑定个人信息" , "targetConfirm": "输入期限不合法！"},
            {"username": "lisi", "password": "123456", "adminUsername": "admin", "adminPassword": "123456","bankCardName": "伊朗中央银行","bankCardNum": Common.generateRandomNumber(16), "buynid": "1", "paypwd": "666666", "balance": "10000","loanMoney": "100","targetbalance": "100000000000010000", "term": "365","confirm": "申请失败，请先绑定个人信息", "targetConfirm": "输入期限不合法！"},
        ]
        for i in datalist:
            sheet.append(list(i.values()))
        workbook.save("用例测试数据.xlsx")
if __name__ == '__main__':
    createTestData()
